package com.xzkydz.sensor.sensor;


import com.xzkydz.sensor.sensor.base.BaseSensorData;

import java.nio.charset.Charset;
import java.util.Arrays;


/**
 * 激光测距解析Bean
 * 激光协议存在两种：一种包的全部长度是 25 、 一种是26 （区别是ASSIC的长度）
 */
public class JiGuangBean25 extends BaseSensorData {

    /**
     * 距离
     */
    public  float juliVel;

    public JiGuangBean25() {

    }

    @Override
    protected void calculate(byte[] recData) {
        super.calculate(recData);

        //七个距离(注意：得到的数据第一位是 ： ，所以不取，从第二位开始取)
        String length0 = new String(bRec, 15, 7, Charset.forName("ASCII")).trim();
        //七个传感器的数据
        if (!"".equals(length0) && length0.matches("[0-9]*\\.{1}\\d*")) {
            juliVel = Float.parseFloat(length0) * 1000f + (float) (Math.random() - 0.5) / 10f;
        }

    }

    @Override
    protected void simulation(int sensorNum) {
        super.simulation(sensorNum);
    }

    @Override
    public String toString() {

        return "JiGuangBean25{" +
                "juliVel=" + juliVel +
                ", bRec=" + Arrays.toString(bRec) +
                ", time=" + time +
                ", addressVel='" + addressVel + '\'' +
                ", batchNumVel='" + batchNumVel + '\'' +
                ", clientCodeVel='" + clientCodeVel + '\'' +
                ", deviceCodeVel='" + deviceCodeVel + '\'' +
                ", sensorTypeVel='" + sensorTypeVel + '\'' +
                ", sensorNumVel=" + sensorNumVel +
                ", dataIndex=" + dataIndex +
                ", dataType='" + dataType + '\'' +
                ", powerVel=" + powerVel +
                ", signalVel=" + signalVel +
                '}';
    }
}
